﻿using Newtonsoft.Json;
using System;

namespace DataProcess.Interface
{
    public static class NewtonJsonExtension
    {
        public static string ToJson<T>(this T t) where T : class
        {
            return JsonConvert.SerializeObject(t);
        }

        public static string FromStruct<T>(this T t) where T : struct
        {
            return JsonConvert.SerializeObject(t);
        }

        public static T FromJson<T>(this string json) where T : class
        {
            return JsonConvert.DeserializeObject<T>(json);
        }

        public static object FromJson(this string json, Type type)
        {
            return JsonConvert.DeserializeObject(json, type);
        }

        public static T ToStruct<T>(this string json) where T : struct
        {
            return JsonConvert.DeserializeObject<T>(json);
        }
    }
}
